﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows.Forms;

namespace ProUpdater
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (!Form1.VersionIF())
                return;
            else
            {
                //先复制自己，然后重新启动自己，防止不能更新自己本身
                if (args.Length > 0 && args[0] == "UpdaterExe")
                {
                    Application.Run(new Form1());
                }
                else
                {
                    string copyPath = $"{Application.StartupPath}\\ProUpdaterCopy.exe";
                    string path = $"{Application.StartupPath}\\ProUpdater.exe";
                    File.Copy(path, copyPath, true);

                    Process pr = new Process();//声明一个进程类对象
                    pr.StartInfo.FileName = copyPath;
                    pr.StartInfo.Arguments = "UpdaterExe";
                    pr.Start();
                    Application.Exit();
                }
            }
        }
    }
}
